import { Router } from "express";
import { upload } from "../middleware/multer";
// import StaticFile from "../db/models/staticFile";
const uploadRouter = Router()

// 上传头像
// uploadRouter.post('/avatar', upload.single('avatar'), async (req, res) => {
//   // 再次上传将原图软删除
//   const files = await StaticFile.findAll({
//     where: {
//       fileType: 'image',
//       routePath: '/avatar'
//     }
//   })
//   files.forEach(async (item) => {
//     await item.destroy()
//   })
//   const file = new StaticFile({
//     originalName: req.file?.originalname!,
//     fileName: req.file?.filename!,
//     filePath: `http://localhost:4000/uploads/image/avatar/${req.file?.filename}`!,
//     fileSize: req.file?.size!,
//     mimeType: req.file?.mimetype!,
//     fileType: 'image',
//     routePath: '/avatar',
//   })
//   await file.save()
//   res.send({
//     code: 200,
//     msg: '上传成功',
//     data: {
//       url: `http://localhost:4000/uploads/image/avatar/${req.file?.filename}`
//     }
//   })
// })

// // 上传壁纸
// uploadRouter.post('/wallpaper', upload.single('wallpaper'), async (req, res) => {
//   const file = new StaticFile({
//     originalName: req.file?.originalname!,
//     fileName: req.file?.filename!,
//     filePath: `http://localhost:4000/uploads/image/wallpaper/${req.file?.filename}`!,
//     fileSize: req.file?.size!,
//     mimeType: req.file?.mimetype!,
//     fileType: 'image',
//     routePath: '/wallpaper',
//   })
//   await file.save()
//   res.send({
//     code: 200,
//     msg: '上传成功',
//     data: {
//       url: `http://localhost:4000/uploads/image/wallpaper/${req.file?.filename}`
//     }
//   })
// })

export default uploadRouter;
